package cn.kgc.ssm.controller;

import cn.kgc.ssm.annotations.Logs;
import cn.kgc.ssm.entity.Active;
import cn.kgc.ssm.enums.Operation;
import cn.kgc.ssm.service.ActiveService;
import cn.kgc.ssm.utils.ResponseResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * @author 课工场
 * @date 2024/3/7
 * @description
 */
@RestController
@RequestMapping("active")
public class ActiveController {

    @Resource
    private ActiveService activeService;

    @GetMapping("page")
    @Logs(description = Operation.SELECT,model = "活动模块")
    public ResponseResult activePage(Integer page,Integer limit,String publisher) {

        return activeService.activePage(page,limit,publisher);
    }

    @PostMapping("add")
    @Logs(description = Operation.ADD,model = "活动模块")
    public ResponseResult addActive(Active active) {

        return activeService.addActive(active);
    }

    @PostMapping("edit")
    @Logs(description = Operation.UPDATE,model = "活动模块")
    public ResponseResult editActive(Active active) {

        return activeService.editActive(active);
    }

    @GetMapping( "getById")
    public ResponseResult  getActiveById(Integer id) {

        return activeService.getActiveById(id);
    }


    @GetMapping( "delete")
    @Logs(description = Operation.DELETE,model = "活动模块")
    public ResponseResult deleteActive(Integer[] ids) {
        Arrays.asList(ids).forEach( id-> System.out.println(id));
        return activeService.deleteActive(ids);

    }

    // 加载前端页面中渲染的最新活动数据
    @GetMapping( "list")
    public ResponseResult activeList() {

        return activeService.activeList();

    }

}
